import fetch from "@/utils/fetch";
import {hex_md5} from '@/utils/md5';



export function DoTestUrlSpeechAssessment(_param) {
    return fetch({
        baseURL: 'https://interface.91118.com',
        url: "/api/Transport/EventHandle",
        method: "post",
        data:  {
            json:JSON.stringify(urlFun("SpeechAssessmentForPoetryGame",_param))
        },
        transformRequest: [function (data) {
            let ret = ''
            for(let it in data){
                ret += encodeURIComponent(it) + '=' +encodeURIComponent(data[it]) + '&'
            }
            return ret
        }],
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
        }
    });
}


export function urlFun(_cmd,_param){
    var _time = new Date().getTime() + '';
    var _uuid = guid();
    var _noce = noce();
    var _key  = 'HTXFV-FH8YX-VCY69-JJGBK-7R6XP';
    var _appJson={
        "AppId":1,
        "Cmd":_cmd,
        "Ver":"1.0.0",
        "UnixTime":_time,
        "SessionId": _uuid,
        "Noce":_noce,
        "AppKey":_key,
        "SKey":md5('1',_cmd,_time,_noce,_key,_uuid),
        "JsonParts":_param,
    }
    return _appJson;
}

function md5(appid,cmd,unixTime,noce,key,sessionId){
    return  hex_md5("Company=hzty&Ver=1.0.0&Methord=MD5&AppID=" + appid + "&Cmd=" + cmd + "&UnixTime=" + unixTime + "&Noce=" + noce + "&AppKey=" + key + "&SessionId=" + sessionId);
}
function guid() {
    function S4() {
        return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
    }
    return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
function noce() {
    return parseInt(Math.random() * 100);
}